$(document).ready(function () {
    if($(".toggle_container").length){       
        
        var autoplayAccordion   = autoplayFeature;
        var clickAllowed        = true;
        
        var autoplay = setInterval(function(){ autoplayAccordion(); }, 5000);
        
        $(".toggle_container .trigger").click(function(){
            if(clickAllowed)
            {
                clearInterval(autoplay);
                if(!$(this).parent().hasClass("active")){
                    $(".contentContainer").animate({width: 'hide'}, function(){ clickAllowed = false; });
                    $(".toggle_container").removeClass("active");
                    $(this).parent().addClass("active");
                    $(this).siblings(".contentContainer").animate({width: 'show'}, function(){ clickAllowed = true; });                 
                }
            }
        });
        
        $(window).blur(function() {
            clearInterval(autoplay);
        });
    }
});

var slideCounter    = 0;

var autoplayFeature = function() { 
    var slides          = $(".toggle_container");
    var totalSlides     = slides.length;    
    var currentSlide    = $(".toggle_container.active");
    var nextSlide       = null;
    
    if(slideCounter === totalSlides - 1)
    {
        slideCounter    = 0;
        nextSlide       =  slides.first();
    }
    else{
        slideCounter++;
        nextSlide       =  currentSlide.next(".toggle_container");
    }
    
    currentSlide.removeClass("active");
    $(".contentContainer").animate({width: 'hide'});
    nextSlide.addClass("active");
    $(".toggle_container.active .contentContainer").animate({width: 'show'}); 
};